package com.cloud.rou.im.client.cmd;

/**
 * <p></p>
 *
 * @author GaoShuangWen
 */
public enum TestEnum {
    LOW(Type.Low.class),
    HIGH(Type.High.class);  //枚举常量必须写在最前面，否则会报错

    interface Type{      //使用interface将子枚举类型组织起来
        enum Low implements Type{
            FIRST("1","first"),
            SECOND("2","second"),
            THIRD("3","third"),
            FOURTH("4","fourth");
            private String code;
            private String description;
            Low(String code,String desciption){
                this.code=code;
                this.description=desciption;
            }
            @Override
            public String getCode(){
                return code;
            }
            @Override
            public String getDescription(){
                return description;
            }
        }
        enum High implements Type{
            FIFTH("5","fifth"),
            SIXTH("6","sixth");
            private String code;
            private String description;
            High(String code,String desciption){
                this.code=code;
                this.description=desciption;
            }
            @Override
            public String getCode(){
                return code;
            }
            @Override
            public String getDescription(){
                return description;
            }
        }
        String getCode();
        String getDescription();
    }

    public Tuple<TestEnum,Type> get(String channel){
        for(TestEnum e:TestEnum.values()){
            for(Type t:e.values){
                if(t.getCode().equals(channel)){
                    return new Tuple<TestEnum, Type>(e,t);
                }
            }
        }
        return null;
    }

    public Type[] getValues(){
        return values;
    }

    Type[] values;
    TestEnum(Class<? extends Type> kind){
        this.values=kind.getEnumConstants();
    }

    public static void main(String[] args){
        TestEnum e=TestEnum.LOW;
        Tuple<TestEnum,Type> tuple=e.get("1");
        if(tuple!=null){
            System.out.println(tuple.getM().name());
            System.out.println(tuple.getT().getCode());
        }
    }

}
